#pragma strict

function Start () {

}

function Update () {
        
 
}

function setOpacity(value:float) {

	var shader1 : Shader = Shader.Find("Diffuse");
    var shader2 : Shader = Shader.Find("Transparent/Diffuse");

	var rComponents : Component[];
    rComponents = gameObject.GetComponentsInChildren(Renderer);
    
    for (var curRenderer : Renderer in rComponents)
    {
        var color : Color;

        for (var mat : Material in curRenderer.materials)
        {
        	if(value == 0.5f) {
	        	if(mat.shader == shader1) {
	        		mat.shader = shader2;
	        	}
	        	else {
	        		//mat.shader = shader1;
	        	}
        	}
        	
            color = mat.color;

            // change alpha for transparency
            color.a = value;

            if (color.a < 0)
            {
                color.a = 0;                    
            }
            mat.color = color;
        }
    }
}